import 'package:back_button_interceptor/back_button_interceptor.dart';
import 'package:flutter/cupertino.dart';

class OverlayUtils {

  static String overlayInterceptor = 'OverlayInterceptor';

  static void insertOverlay({required BuildContext context, required OverlayEntry entry}) {
    // Overlay.of(context).insert(entry!);

    BackButtonInterceptor.add((bool stopDefaultButtonEvent, RouteInfo info) {
      entry.remove();
      BackButtonInterceptor.removeByName(overlayInterceptor);
      return true;
    }, name: overlayInterceptor);
  }

  static void removeOverlay() {
    BackButtonInterceptor.removeByName(overlayInterceptor);
  }
}